var url = require("url");
var requestHandlers = require("./requestHandlers");
var util = require("util");

var handle = {}

handle["/upload"] = requestHandlers.upload;
handle["/fetch"] = requestHandlers.fetch;
handle["/"] = requestHandlers.fetch;

function route(request, response, postData) {
    var pathname = url.parse(request.url).pathname;
    if (typeof handle[pathname] == "function") {
	handle[pathname](response, postData);
    } else {
	requestHandlers.error(response);
    }
}

exports.route = route;